|
Many programming languages and other computer files have a directive, often called include (as well as copy and import ), that causes the contents of a second file to be inserted into the original file. These included files are called copybooks or header files. They are often used to define the physical layout of program data, pieces of procedural code and/or forward declarations while promoting encapsulation and the reuse of code.== Purpose == The include directive allows libraries of code to be developed which help to: * ensure that everyone uses the same version of a data layout definition or procedural code throughout a program. * easily cross-reference where components are used in a system. * easily change programs when needed (only one master copy to change). * save time by not needing to code extensive data layouts (minor, but useful). An example situation which benefits from the use of an include directive is when referring to functions in a different file. Suppose we have a function add in one file, which is then declared (with a function prototype) and then referred to in a second source file as follows:One drawback of this method is that the prototype must be present in all files that use the function. Another drawback is that if the return type or arguments of the function are changed, these prototypes will have to be updated. Putting the prototype in a single, separate file avoids these problems. Assuming the prototype is moved to the file add.h , the second source file can then become:Now, every time the code is compiled, the latest function prototypes in add.h will be included in the files using them, avoiding potentially disastrous errors.抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)』 ■ウィキペディアで「Include directive」の詳細全文を読む スポンサード リンク
|